package com.njtoyo.taxi.admin.logic.allowance;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.njtoyo.taxi.admin.mapper.master.entity.DriverReward;
import com.njtoyo.taxi.admin.mapper.master.enums.DriverRewardCategory;
import com.njtoyo.taxi.admin.mapper.master.mapper.DriverRewardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class DriverRewardLogic {

    @Autowired
    private DriverRewardMapper driverRewardMapper;

    public BigDecimal getAmountByCategory(Date start, Date end, List<DriverRewardCategory> categoryList) {
        QueryWrapper<DriverReward> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("category", categoryList)
                .between("created_at", start, end)
                .select("IFNULL(SUM(amount), 0)");

        List<Object> res = driverRewardMapper.selectObjs(queryWrapper);

        return (BigDecimal) res.get(0);
    }
}
